﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace EncryptHelper
{
    public class EncryptHelper
    {
        /// <summary>
        /// MD5加密算法
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetMD5Hash(string str)
        {
            using (MD5 md5Obj = MD5.Create())
            {
                //另一种MD5的方式
                // MD5 md5Obj = new MD5CryptoServiceProvider();
                byte[] bytes = Encoding.UTF8.GetBytes(str);
                byte[] md5byte = md5Obj.ComputeHash(bytes);
                StringBuilder bulider = new StringBuilder();
                for (int i = 0; i < md5byte.Length; i++)
                {
                    bulider.Append(md5byte[i].ToString("X2"));
                }
                return bulider.ToString();
            };
        }
    }
}
